package fontys.time;

import java.util.ArrayList;
import java.util.Iterator;

/**
 *
 * @author Elton Figaroa, Implementatie: Willem Sporen
 */
class Contact {


    /**
     * Name of the Contact.
     */
    private String myName;
    /**
     * List of appointments this contact has.
     */
    private ArrayList<Appointment> appointments;

    /**
     * creation of a Contact with a name
     *
     * @param name is the name of the contact
     *
     */
    public Contact(final String name) {
        myName = name;
        appointments = new ArrayList<Appointment>();
    }

    /**
     *
     * @return the name of the contact
     */
    public final String getName() {
        return myName;
    }
    /**
     *
     * @param a appointment that needs to be added
     * @return returns true if the appointment is correctly added
     */
    protected final boolean addAppointment(final Appointment a) {
        for (Appointment ap: appointments) {
            if (ap.getPeriod().isPartOf(a.getPeriod())) {
                return false;
            } else if (a.getPeriod().isPartOf(ap.getPeriod())) {
                return false;
            }
        }
        return appointments.add(a);
    }

    /**
     *
     * @param a appointment that needs to be removed
     */
    protected final void removeAppointment(final Appointment a) {
         appointments.remove(a);
    }

    /**
     *
     * @return a datacollection of all the appointments
     */
    public final Iterator<Appointment> appointments() {
        return appointments.iterator();
    }

}
